import type { CategoryDTO } from './data'
import { deleteCategoriesApi, getCategoriesApi, getTagsApi, putCategoryApi } from './api'
import { ElMessage } from 'element-plus'

export const getCategories = async (dto: CategoryDTO.Get) => {
  dto.pageSize = dto.pageSize ?? 10
  const res = await getCategoriesApi(dto)
  return res.data
}

export const putCategory = async (dto: CategoryDTO.Put) => {
  const res = await putCategoryApi(dto)
  ElMessage.success(dto.id ? '修改成功' : '添加成功')
  return res.data
}

export const deleteCategories = async (dto: CategoryDTO.Delete) => {
  const res = await deleteCategoriesApi(dto)
  ElMessage.success('删除成功')
  return res.data
}

export const getTags = async () => {
  const res = await getTagsApi()
  return res.data
}
